package com.elong.spring.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class PrivateCarReflect {

    public static void main(String[] args) throws Exception {
	ClassLoader loader = Thread.currentThread().getContextClassLoader();
	Class<?> clazz = loader.loadClass("com.elong.common.spring.reflect.PrivateCar");
	PrivateCar pCar = (PrivateCar) clazz.newInstance();
	
	//获取field
	Field colorField = clazz.getDeclaredField("color");
	colorField.setAccessible(true);
	colorField.set(pCar, "红色");
	
	Method driveMethod = clazz.getDeclaredMethod("drive", (Class<?>[])null);
	driveMethod.setAccessible(true);
	driveMethod.invoke(pCar, (Object[])null);
    }
}
